<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<!DOCTYPE html>
<html>

<head>
    <base href="/oa/" />
    <title>襄阳蓝芯智能化办公系统</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="${pageContext.request.contextPath}/static/bootstrap-3.3.5/css/bootstrap.css" rel="stylesheet">
    <style>
        /*定义类名为.thead-blue的样式*/
        .thead-blue {
            color: #fff;
            font-weight: bold;
            background-color: #337ab7;
        }
    </style>
    <script src="${pageContext.request.contextPath}/static/jquery/jquery-1.10.2.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/bootstrap-3.3.5/js/bootstrap.min.js"></script>
</head>
<body>

<!-- 搜索 -->
<div class="panel panel-primary">
    <div class="panel-heading">
        <h4 class="panel-title">我的购买申请单</h4>
    </div>
    <div class="panel-body">
        <form action="${pageContext.request.contextPath}/zc-assetpurchaseapply/tomyallzcassetpurchaseapplylist" id="seachform" method="post" class="form-horizontal" role="form">

            <div class="form-group">
                <div class="col-md-5">
                    <label for="docNo" class="col-md-4 control-label">申请单号</label>
                    <div class="col-md-8">
                        <input type="text" id="docNo" name="docNo" class="form-control"
                               placeholder="请输入申请单号" value="${docNo}"> <input
                            type="hidden" name="page" id="page" value="1">
                        <input type="hidden" name="pageSize" id="pageSize"
                               value="5">
                    </div>
                </div>
                <div class="col-md-5">
                    <label for="deptid" class="col-md-4 control-label">申请单状态</label>
                    <div class="col-md-8">
                        <select name="status" class="form-control">
                            <option value="">--申请单状态--</option>
                            <option value="B" ${param.status == 'B' ? 'selected' : ''}>--待报价--</option>
                            <option value="W" ${param.status == 'W' ? 'selected' : ''}>--未提交--</option>
                            <option value="O" ${param.status == 'O' ? 'selected' : ''}>--审批中--</option>
                            <option value="Y" ${param.status == 'Y' ? 'selected' : ''}>--审批通过--</option>
                            <option value="N" ${param.status == 'N' ? 'selected' : ''}>--审批不通过--</option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="form-group">

                <div class="col-md-5">
                    <label for="jobid" class="col-md-4 control-label">提交时间</label>
                    <div class="col-md-8">
                        <input type="date" id="submitDate" name="submitDate"
                               class="form-control" value="${submitDate}">
                    </div>
                </div>

                <div class="col-md-5">
                    <label for="deptid" class="col-md-4 control-label"></label>
                    <div class="col-md-8">
                        <button type="button" onclick="searchBtn()" class="btn btn-success">搜索购买申请</button>
                        <button type="button" onclick="resetSearch()"
                                class="btn btn-warning">取消搜索</button>
                        <a type="button" href="${pageContext.request.contextPath}/zc-assetpurchaseapply/toeditZcAssetpurchaseapply" class="btn btn-info">添加购买申请</a>
                    </div>
                </div>
            </div>

        </form>
    </div>
</div>

<!-- 列表 -->
<div class="panel panel-primary">
    <table class="table table-bordered table-hover">
        <thead>
        <tr class="thead-blue" align="center">
            <td>申请单编号</td>
            <td>申请单创建人</td>
            <td>申请单申请人</td>
            <td>创建时间</td>
            <td>提交时间</td>
            <td>申请单状态</td>
            <td>操作</td>
        </tr>
        </thead>
        <tbody>
        <!-- 使用c:forEach循环展示数据 -->
        <c:forEach items="${allzcassetpurchaseapplyVoPage}" var="purchase">
            <tr align="center">
                <td>${purchase.docNo}</td>
                <td>${purchase.creator}</td>
                <td>${purchase.proposer}</td>
                <!-- 日期格式化 -->
                <td><fmt:formatDate value="${purchase.createDate}" pattern="yyyy-MM-dd HH:mm:ss" /></td>
                <td><fmt:formatDate value="${purchase.submitDate}" pattern="yyyy-MM-dd HH:mm:ss" /></td>
                <!-- 状态中文转换 -->
                <td>
                    <c:choose>
                        <c:when test="${purchase.status == 'B'}">待报价</c:when>
                        <c:when test="${purchase.status == 'W'}">未提交</c:when>
                        <c:when test="${purchase.status == 'O'}">审批中</c:when>
                        <c:when test="${purchase.status == 'Y'}">审批通过可购买</c:when>
                        <c:when test="${purchase.status == 'N'}">审批不通过</c:when>
                        <c:otherwise>${purchase.status}</c:otherwise>
                    </c:choose>
                </td>
                <!-- 操作按钮 -->
                <td>
                    <button type="button" onclick="location.href='${pageContext.request.contextPath}/zc-assetpurchaseapplydetails/zcAssetpurchaseapplyInfo?oid=${purchase.oid}'"
                            class="btn btn-info btn-xs">详情</button>
                    <c:if test="${purchase.status == 'W'}">
                        <button type="button" onclick="subZcAssetpurchaseapply1(${purchase.oid})" class="btn btn-success btn-xs">提交</button>
                        <button type="button" onclick="location.href='${pageContext.request.contextPath}/zc-assetpurchaseapply/toeditZcAssetpurchaseapply?oid=${purchase.oid}'" class="btn btn-primary btn-xs">修改</button>
                    </c:if>
                    <c:if test="${purchase.status == 'B'}">
                        <button type="button" onclick="subZcAssetpurchaseapply2(${purchase.oid})" class="btn btn-success btn-xs">提交审批</button>
                        <button type="button" onclick="location.href='${pageContext.request.contextPath}/zc-assetpurchaseapply/toBaojia?oid=${purchase.oid}'" class="btn btn-primary btn-xs">去报价</button>
                    </c:if>
                    <c:if test="${purchase.status == 'B' || purchase.status == 'W'}">
                        <button type="button" onclick="deleteAssetpurchaseapply(${purchase.oid})" class="btn btn-danger btn-xs" data-toggle="modal" data-target="#confirmModal">删除</button>
                    </c:if>
                    <c:if test="${purchase.status == 'O' || purchase.status == 'Y' || purchase.status == 'N'}">
                    <button type="button" onclick="location.href='${pageContext.request.contextPath}/judge/approval/getApprovalLog?docNo=${purchase.docNo}'"
                            class="btn btn-success btn-xs">审批记录</button>
                    </c:if>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
</div>

<!-- 分页 -->
<div class="input-group col-md-6 col-md-offset-3">
    <div class="text-center">
        <div class="btn-group">
            <!-- 首页按钮 -->
            <c:choose>
                <c:when test="${pageNum > 1}">
                    <button onclick="gotoPage(1, ${pageSize})" class="btn btn-primary" type="button">首页</button>
                </c:when>
                <c:otherwise>
                    <button class="btn btn-primary disabled" type="button">首页</button>
                </c:otherwise>
            </c:choose>

            <!-- 上一页按钮 -->
            <c:choose>
                <c:when test="${pageNum > 1}">
                    <button onclick="gotoPage(${pageNum - 1}, ${pageSize})" class="btn btn-primary" type="button">上一页</button>
                </c:when>
                <c:otherwise>
                    <button class="btn btn-primary disabled" type="button">上一页</button>
                </c:otherwise>
            </c:choose>

            <!-- 当前页/总页数 -->
            <button class="btn btn-primary disabled" type="button">
                当前第${pageNum}/${pages}页
            </button>

            <!-- 每页显示条数下拉框 -->
            <div class="btn-group">
                <button type="button" class="btn btn-primary dropdown-toggle"
                        data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    每页显示${pageSize}条 <span class="caret"></span>
                </button>
                <ul class="dropdown-menu">
                    <li><a href="javascript:gotoPage(1,5)">每页显示5条</a></li>
                    <li><a href="javascript:gotoPage(1,10)">每页显示10条</a></li>
                    <li><a href="javascript:gotoPage(1,15)">每页显示15条</a></li>
                    <li><a href="javascript:gotoPage(1,20)">每页显示20条</a></li>
                </ul>
            </div>

            <!-- 总记录数 -->
            <button class="btn btn-primary disabled" type="button">
                共${total}条记录
            </button>

            <!-- 下一页按钮 -->
            <c:choose>
                <c:when test="${pageNum < pages}">
                    <button onclick="gotoPage(${pageNum + 1}, ${pageSize})" class="btn btn-primary" type="button">下一页</button>
                </c:when>
                <c:otherwise>
                    <button class="btn btn-primary disabled" type="button">下一页</button>
                </c:otherwise>
            </c:choose>

            <!-- 尾页按钮 -->
            <c:choose>
                <c:when test="${pageNum < pages}">
                    <button onclick="gotoPage(${pages}, ${pageSize})" class="btn btn-primary" type="button">尾页</button>
                </c:when>
                <c:otherwise>
                    <button class="btn btn-primary disabled" type="button">尾页</button>
                </c:otherwise>
            </c:choose>
        </div>
    </div>
</div>

<br>
<br>
<br>



<!-- 模态框（Modal） -->
<div class="modal fade" id="confirmModal" tabindex="-1" role="dialog" aria-labelledby="confirmModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="confirmModalLabel">
                    提示
                </h4>
            </div>
            <div class="modal-body">
                确认删除吗？
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                </button>
                <button type="button" id="subconfirm" class="btn btn-primary">
                    提交更改
                </button>
            </div>
        </div>
    </div>
</div>
<script>
    $(document).ready(function(){
        $("#subconfirm").click(function(){
            deleteConfirm();
            $('#confirmModal').modal('hide');
        });

    });
</script>







<script type="text/javascript">
    $(document).ajaxError(function(event,xhr) {
        if(xhr.status=="403"){//没有权限
            document.location.href = xhr.getResponseHeader("url");
        }else if(xhr.status!="200"){
            //alert("服务器错误!");
            console.log("服务器错误!");
        }
    });
</script>

<!-- 模态框（Modal） -->
<div class="modal fade" id="alertMsgModal" tabindex="-1" role="dialog" aria-labelledby="alertMsgModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-xs">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="alertMsgModalLabel">
                    提示
                </h4>
            </div>
            <div class="modal-body" id="alertmsg">
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>

</body>
<script type="text/javascript">
    function resetSearch() {

        $("#docNo").val("");
        $("#proposer").val("");
        $("#empName").val("");
        $("#submitDate").val("");
        $("select[name='status']").val("");
        $("#page").val(1);
        $("#seachform").submit();
    }
    function gotoPage(page,pageSize){
        $("#page").val(page);
        $("#pageSize").val(pageSize);
        $("#seachform").submit();
    }
    function searchBtn(){
        $("#page").val(1);
        $("#seachform").submit();
    }


    function subZcAssetpurchaseapply1(oid){
        $.get("${pageContext.request.contextPath}/zc-assetpurchaseapply/subZcAssetpurchaseapply1",{"oid":oid},function(s){
            if(s==true){
                document.location.href="${pageContext.request.contextPath}/zc-assetpurchaseapply/tomyallzcassetpurchaseapplylist";
            }else{
                $("#alertmsg").text("提交失败!当前申请单没有购买明细!");
                $('#alertMsgModal').modal('show');
            }
        });
    }

    function subZcAssetpurchaseapply2(oid){
        $.get("${pageContext.request.contextPath}/zc-assetpurchaseapply/subZcAssetpurchaseapply2",{"oid":oid},function(s){
            if(s==true){
                document.location.href="${pageContext.request.contextPath}/zc-assetpurchaseapply/tomyallzcassetpurchaseapplylist";
            }else{
                $("#alertmsg").text("提交失败!当前申请单没有购买明细或没有报价!");
                $('#alertMsgModal').modal('show');
            }
        });
    }

    var deleteoid;
    function deleteAssetpurchaseapply(oid){
        deleteoid = oid;
    }
    function deleteConfirm(){
        $.get("${pageContext.request.contextPath}/zc-assetpurchaseapply/deleteAssetpurchaseapply",{"oid":deleteoid},function(s){
            if(s==true){
                document.location.href="${pageContext.request.contextPath}/zc-assetpurchaseapply/tomyallzcassetpurchaseapplylist";
            }else{
                $("#alertmsg").text("删除失败!");
                $('#alertMsgModal').modal('show');
            }
        });
    }
</script>
</html>
